import { View } from '@tarojs/components';
import React from 'react';
import { RoundNum } from '@/utils/helper';
import styles from './index.module.scss';

const Summation = ({ summation, handleSave, className = '' }) => {
  const [p1, p2] = parseFloat(summation?.submitTotalPrice).toFixed(2).split('.');

  return (
    <View className={`${styles.Summation} ${className}`}>
      <View className="price-detail">
        应付：
        <View className="price">
          <View className="unit customePageStyle">¥</View>
          <View className="value-1 customePageStyle">{p1}</View>
          <View className="value-2 customePageStyle">.{p2}</View>
        </View>

        <View className="discount">
          {summation?.discountPrice > 0 ? '共省¥' + RoundNum(parseFloat(summation?.discountPrice),2) : ''}
        </View>
      </View>

      <View className="btn customePageBackgroundStyle" onClick={handleSave}>
        <View className="txt">提交订单</View>
      </View>
    </View>
  );
};

export default Summation;
